package com.hp.easyBuy.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hp.easyBuy.entity.TOrder;
import com.hp.easyBuy.service.OrderService;
import com.hp.easyBuy.utils.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("order")
public class OrderController {
    @Resource
    private OrderService orderService;
    //订单列表分页条件查询
    @PostMapping("doPage")
    public R<Page<TOrder>> doPage(Integer currentPage, Integer pageSize, @RequestBody Map<String,Object> params){
        Page<TOrder> page = orderService.page(currentPage, pageSize, params);
        return R.success(page);
    }

    //订单确认收货
    @GetMapping("update")
    public R updateStatus(Integer id){
        boolean update = orderService.update(id);
        if(update){
            return R.success();
        }
        else {
            return R.error();
        }
    }

    //订单查看详情
    @GetMapping("details")
    public R details(Integer id){
        TOrder order = orderService.details(id);
        return R.success(order);
    }
    @RequestMapping("/account")
    public R account(@RequestParam Long userId, @RequestParam Long addressId){
        try {
            orderService.account(userId,addressId);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error();
        }
        return R.success();
    }
}
